home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / macintosh technotes and q&as / technotes / tn / rd_1077.hqx / Routine Descriptors in lib / DemoApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-06  |  2.3 KB  |  111 lines

  1. #include <FragLoad.h>
  2. #include <Types.h>
  3. #include <Memory.h>
  4. #include <Quickdraw.h>
  5. #include <Fonts.h>
  6. #include <Events.h>
  7. #include <Menus.h>
  8. #include <MixedMode.h>
  9. #include <Windows.h>
  10. #include <TextEdit.h>
  11. #include <Dialogs.h>
  12. #include <OSUtils.h>
  13. #include <ToolUtils.h>
  14. #include <Types.h>
  15. #include <SegLoad.h>
  16.  
  17. #include "DemoLib.h"
  18.  
  19. /* Prototypes */
  20.  
  21. void Initialize(void);
  22.  
  23. // 
  24. //    Main body of program
  25. //
  26.  
  27. void main(void)
  28. {
  29.     long    tLong = 0;
  30.  
  31.     Initialize();
  32.  
  33.     Set_DemoValue(tLong);
  34.     Do_Demo();
  35.     tLong = Get_DemoValue();
  36.  
  37.     Set_DemoValue(tLong + 1);
  38.     Do_Demo();
  39.     tLong = Get_DemoValue();
  40.  
  41.     Set_DemoValue(tLong + 1);
  42.     Do_Demo();
  43.     tLong = Get_DemoValue();
  44.  
  45.     Set_DemoValue(tLong + 1);
  46.     Do_Demo();
  47.     tLong = Get_DemoValue();
  48.  
  49.     Set_DemoValue(tLong + 1);
  50.     Do_Demo();
  51.     tLong = Get_DemoValue();
  52.  
  53.     do {} while (!Button());
  54. }
  55.  
  56. // 
  57. //    Initialize everything for the program, make sure we can run
  58. //
  59.  
  60. void Initialize(void)
  61. {
  62.     WindowPtr    mainPtr;
  63.     OSErr        error;
  64.     SysEnvRec    theWorld;
  65.     Rect        windRect;
  66.         
  67.     //
  68.     //    Test the computer to be sure we can do color.  
  69.     //    If not we would crash, which would be bad.  
  70.     //    If we can’t run, just beep and exit.
  71.     //
  72.  
  73.     error = SysEnvirons(1, &theWorld);
  74.     if (theWorld.hasColorQD == false) {
  75.         SysBeep(50);
  76.         ExitToShell();                    /* If no color QD, we must leave. */
  77.     }
  78.     
  79.     /* Initialize all the needed managers. */
  80.     InitGraf(&qd.thePort);
  81.     InitFonts();
  82.     InitWindows();
  83.     InitMenus();
  84.     TEInit();
  85.     InitDialogs(nil);
  86.     InitCursor();
  87.  
  88.     //
  89.     //    To make the Random sequences truly random, we need to make the seed start
  90.     //    at a different number.  An easy way to do this is to put the current time
  91.     //    and date into the seed.  Since it is always incrementing the starting seed
  92.     //    will always be different.  Don’t for each call of Random, or the sequence
  93.     //    will no longer be random.  Only needed once, here in the init.
  94.     //
  95.     GetDateTime((unsigned long*) &qd.randSeed);
  96.  
  97.     //
  98.     //    Make a new window for drawing in, and it must be a color window.  
  99.     //    The window is full screen size, made smaller to make it more visible.
  100.     //
  101.     windRect = qd.screenBits.bounds;
  102.     InsetRect(&windRect, 50, 50);
  103.     mainPtr = NewCWindow(nil,&windRect,"\pDemoApp",true,documentProc,(WindowPtr) -1,false,0);
  104.  
  105.     SetPort(mainPtr);                        /* set window to current graf port */
  106.     TextSize(24);                        /* smaller font for drawing. */
  107.  
  108.     MoveTo(50,50);
  109.     DrawString("\pDemoApp");
  110. }
  111.